package com.example.baselib.dialog

import android.content.DialogInterface
import android.view.View
import androidx.lifecycle.viewModelScope
import com.example.baselib.BaseViewModel
import com.example.baselib.R
import kotlinx.coroutines.cancel
import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.isActive

/**
 * Author: sxygsj
 * Date: 2020/4/13 16:26
 * Description: 公用Loading
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
class LoadingDialog(private val viewModel: BaseViewModel) : BaseDialogFragment() {
    override fun getContentLayout(): Int {
        return R.layout.dialog_loading
    }

    override fun initView(view: View) {
    }
    override fun initData() {
    }

    override fun onDismiss(dialog: DialogInterface) {
        super.onDismiss(dialog)

        //手动取消时关掉协程？？
        if(viewModel.viewModelScope.coroutineContext.isActive) {
            viewModel.viewModelScope.coroutineContext.cancelChildren()
        }
    }
}